<!--    引入uE编辑器的js-->
<script charset="utf-8" src="/js/ue/ueditor.config.js"></script>
<script charset="utf-8" src="/js/ue/ueditor.all.min.js"></script>
<script charset="utf-8" src="/js/ue/lang/zh-cn/zh-cn.js"></script>
<script charset="utf-8" src="/js/jquery.tags.min.js"></script>
<div class="container">
    <form id="blog-form-id" method="post" class="form-horizontal">
        <input type="hidden" name="<?=$this->security->getTokenKey()?>" value="<?=$this->security->getToken()?>">
        <div class="form-group">
            <label for="error-id" class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <p id="title-error" class="text-danger"><?=$error;?></p>
            </div>
        </div>
        <input type="hidden" name="tags" id="hidden-tags">
        <div class="form-group">
            <label for="title-id" class="col-sm-2 control-label">Title</label>
            <div class="col-sm-3">
                <input type="text" class="form-control" value="<?=$title?>" id="title-id" name="title" placeholder="please input title" required>
            </div>
        </div>
        <div class="form-group">
            <label for="content-id" class="col-sm-2 control-label">Content</label>
            <div class="col-sm-3">
                <script type="text"  required name="content" id="content-id" style="width:800px;height:400px;"></script>
            </div>
        </div>
    </form>
    <div class="form-horizontal">
        <div class="form-group">
            <label for="tags" class="col-sm-2 control-label">Tags</label>
            <div class="col-sm-7">
                <input id="tags" type="text" data-toggle="tags" />
            </div>
            <div class="col-sm-3">
                <p id="tag-error" class="text-danger"><?=$error;?></p>
            </div>
        </div>
        <div class="form-group">
            <label for="button-id" class="col-sm-2 control-label"></label>
            <div class="col-sm-3">
                <input type='submit' id="button-id" onclick="formSubmit()" class="btn btn-success btn-block"  value="submit">
            </div>
        </div>
    </div>
</div>
<script>
    var content = '<?=$content?>';
    var ue = UE.getEditor('content-id');
    ue.addListener("ready", function () {
        // editor准备好之后才可以使用
        ue.setContent(content);

    });
    function  check() {
        if($('#title-id').val().trim() == '') {
            $('#title-error').html('标题不能为空');
            return false;
        }
        if (ue.getContent().trim() == '') {
            $('#title-error').html('内容不能为空');
            return false;
        }
        return true;
    }
    function formSubmit() {
        if (!check()) {
            return false;
        }
        var form = document.getElementById('blog-form-id');
        var tags = $('#tags').val();
        $('#hidden-tags').val(tags);
        return form.submit();
    }
</script>